
package com.yuanmei.model;

import android.util.Log;

import com.yuanmei.common.Utils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Locale;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import ir.mirrajabi.searchdialog.core.Searchable;

public class TdxStockInfo extends RealmObject implements Searchable {
    @PrimaryKey
    private int code; // 1
    private String name, industry, area; // 3
    private String pinyin, timeToMarket, financialUpdate; // 3

    private float outstanding, totalShares, totalAssets, fixedAssets, netAssets; // 5
    private float operatingRevenue, operatingProfit, totalProfit; //4

    private float investmentIncome, netProfitRate, grossProfitRate, afterTaxProfit;//4
    private float netProfitAfterDeductionNonRecurring, undividedProfit; // 2
    private float operatingCashFlow, totalCashFlow; // 2
    private float yearOnYearProfit, yearOnYearRevenue; // 2

    private float netProfit, RDExpense, netCashFlowPerShare; //3
    private float equityRatio, netProfitMargin, operatingProfitMargin, dividendYieldRatio; //4
    private float assetDebtRatio, priceToBookRatio, priceToSaleRatio, priceToCashRatio; //4

    // total fields = 37

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public float getOperatingCashFlow() {
        return this.operatingCashFlow;
    }

    public void setOperatingCashFlow(float operatingCashFlow) {
        this.operatingCashFlow = operatingCashFlow;
    }

    public float getTotalCashFlow() {
        return this.totalCashFlow;
    }

    public void setTotalCashFlow(float totalCashFlow) {
        this.totalCashFlow = totalCashFlow;
    }

    public float getYearOnYearProfit() {
        return this.yearOnYearProfit;
    }

    public void setYearOnYearProfit(float yearOnYearProfit) {
        this.yearOnYearProfit = yearOnYearProfit;
    }

    public float getYearOnYearRevenue() {
        return this.yearOnYearRevenue;
    }

    public void setYearOnYearRevenue(float yearOnYearRevenue) {
        this.yearOnYearRevenue = yearOnYearRevenue;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPinyin() {
        return this.pinyin;
    }

    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    public String getIndustry() {
        return this.industry;
    }

    public void setIndustry(String industry) {
        this.industry = industry;
    }

    public String getArea() {
        return this.area;
    }

    public void setArea(String area) {
        this.area = area;
    }


    public float getOutstanding() {
        return this.outstanding;
    }

    public void setOutstanding(float outstanding) {
        this.outstanding = outstanding;
    }

    public float getTotalShares() {
        return this.totalShares;
    }

    public void setTotalShare(float totals) {
        this.totalShares = totals;
    }

    public float getTotalAssets() {
        return this.totalAssets;
    }

    public void setTotalAssets(float totalAssets) {
        this.totalAssets = totalAssets;
    }

    public float getFixedAssets() {
        return this.fixedAssets;
    }

    public void setFixedAssets(float fixedAssets) {
        this.fixedAssets = fixedAssets;
    }

    public float getTotalProfit() {
        return this.totalProfit;
    }

    public void setTotalProfit(float totalProfit) {
        this.totalProfit = totalProfit;
    }

    public float getNetAssets() {
        return this.netAssets;
    }

    public void setNetAssets(float netAssets) {
        this.netAssets = netAssets;
    }

    public float getOperatingRevenue() {
        return this.operatingRevenue;
    }

    public void setOperatingRevenue(float operatingRevenue) {
        this.operatingRevenue = operatingRevenue;
    }

    public float getOperatingProfit() {
        return this.operatingProfit;
    }

    public void setOperatingProfit(float operatingProfit) {
        this.operatingProfit = operatingProfit;
    }

    public float getInvestmentIncome() {
        return this.investmentIncome;
    }

    public void setInvestmentIncome(float investmentIncome) {
        this.investmentIncome = investmentIncome;
    }

    public float getNetProfitRate() {
        return this.netProfitRate;
    }

    public void setNetProfitRate(float netProfitRate) {
        this.netProfitRate = netProfitRate;
    }

    public float getGrossProfitRate() {
        return this.grossProfitRate;
    }

    public void setGrossProfitRate(float grossProfitRate) {
        this.grossProfitRate = grossProfitRate;
    }

    public float getAfterTaxProfit() {
        return this.afterTaxProfit;
    }

    public void setAfterTaxProfit(float afterTaxProfit) {
        this.afterTaxProfit = afterTaxProfit;
    }

    public float getNetProfitAfterDeductionNonRecurring() {
        return this.netProfitAfterDeductionNonRecurring;
    }

    public void setNetProfitAfterDeductionNonRecurring(float netProfitAfterDeductionNonRecurring) {
        this.netProfitAfterDeductionNonRecurring = netProfitAfterDeductionNonRecurring;
    }

    public float getUndividedProfit() {
        return this.undividedProfit;
    }

    public void setUndividedProfit(float undividedProfit) {
        this.undividedProfit = undividedProfit;
    }

    public String getTimeToMarket() {
        return this.timeToMarket;
    }

    public void setTimeToMarket(String timeToMarket) {
        this.timeToMarket = timeToMarket;
    }

    public String getFinancialUpdate() {
        return this.financialUpdate;
    }

    public void setFinancialUpdate(String financialUpdate) {
        this.financialUpdate = financialUpdate;
    }

    public float getNetProfit() {
        return this.netProfit;
    }

    public void setNetProfit(float netProfit) {
        this.netProfit = netProfit;
    }

    public float getRDExpense() {
        return this.RDExpense;
    }

    public void setRDExpense(float rdexpense) {
        this.RDExpense = rdexpense;
    }

    public float getNetCashFlowPerShare() {
        return this.netCashFlowPerShare;
    }

    public void setNetCashFlowPerShare(float ncfps) {
        this.netCashFlowPerShare = ncfps;
    }

    public float getEquityRatio() {
        return this.equityRatio;
    }

    public void setEquityRatio(float value) {
        this.equityRatio = value;
    }

    public float getNetProfitMargin() {
        return this.netProfitMargin;
    }

    public void setMetProfitMargin(float value) {
        this.netProfitMargin = value;
    }

    public float getOperatingProfitMargin() {
        return this.operatingProfitMargin;
    }

    public void setOperatingProfitMargin(float value) {
        this.operatingProfitMargin = value;
    }

    public float getDividendYieldRatio() {
        return this.dividendYieldRatio;
    }

    public void setDividendYieldRatio(float value) {
        this.dividendYieldRatio = value;
    }

    public float getAssetDebtRatio() {
        return this.assetDebtRatio;
    }

    public void setAssetDebtRatio(float value) {
        this.assetDebtRatio = value;
    }

    public float getPriceToBookRatio() {
        return this.priceToBookRatio;
    }

    public void setPriceToBookRatio(float value) {
        this.priceToBookRatio = value;
    }

    public float getPriceToSaleRatio() {
        return this.priceToSaleRatio;
    }

    public void setPriceToSaleRatio(float value) {
        this.priceToSaleRatio = value;
    }

    public float getPriceToCashRatio() {
        return this.priceToCashRatio;
    }

    public void setPriceToCashRatio(float value) {
        this.priceToCashRatio = value;
    }

    public TdxStockInfo() {
        super();
    }

    public TdxStockInfo(JSONObject joInfo) {
        try {
            this.name = joInfo.getString("name");
            this.industry = joInfo.getString("industry");
            this.area = joInfo.getString("area");
            this.pinyin = joInfo.getString("pinyin");
            this.timeToMarket = joInfo.getString("timeToMarket");

            this.outstanding = (float) joInfo.getDouble("outstanding");
            this.totalShares = (float) joInfo.getDouble("totalShares");
            this.totalAssets = (float) joInfo.getDouble("totalAssets");
            this.fixedAssets = (float) joInfo.getDouble("fixedAssets");
            this.netAssets = (float) joInfo.getDouble("netAssets");

            this.operatingRevenue = (float) joInfo.getDouble("operatingRevenue");
            this.operatingProfit = (float) joInfo.getDouble("operatingProfit");
            this.totalProfit = (float) joInfo.getDouble("totalProfit");

            this.investmentIncome = (float) joInfo.getDouble("investmentIncome");
            this.netProfit = (float) joInfo.getDouble("netProfit");
            this.RDExpense = (float) joInfo.getDouble("RDExpense");
            this.netProfitRate = (float) joInfo.getDouble("netProfitRate");
            this.grossProfitRate = (float) joInfo.getDouble("grossProfitRate");
            this.afterTaxProfit = (float) joInfo.getDouble("afterTaxProfit");

            this.netProfitAfterDeductionNonRecurring =
                    (float) joInfo.getDouble("netProfitAfterDeductionNonRecurring");
            this.undividedProfit = (float) joInfo.getDouble("undividedProfit");
            this.operatingCashFlow = (float) joInfo.getDouble("operatingCashFlow");
            this.totalCashFlow = (float) joInfo.getDouble("totalCashFlow");
            this.yearOnYearProfit = (float) joInfo.getDouble("yearOnYearProfit");
            this.yearOnYearRevenue = (float) joInfo.getDouble("yearOnYearRevenue");
            this.financialUpdate = joInfo.getString("financialUpdate");

            this.netCashFlowPerShare = (float) joInfo.getDouble("netCashFlowPerShare");
            this.equityRatio = (float) joInfo.getDouble("equityRatio");
            this.netProfitMargin = (float) joInfo.getDouble("netProfitMargin");
            this.operatingProfitMargin = (float) joInfo.getDouble("operatingProfitMargin");
            this.dividendYieldRatio = (float) joInfo.getDouble("dividendYieldRatio");
            this.assetDebtRatio = (float) joInfo.getDouble("assetDebtRatio");
            this.priceToSaleRatio = (float) joInfo.getDouble("priceToSaleRatio");
            this.priceToCashRatio = (float) joInfo.getDouble("priceToCashRatio");
            this.priceToBookRatio = (float) joInfo.getDouble("priceToBookRatio");

            String strCode = joInfo.getString("code");
            this.code = Utils.safeToInteger(strCode);
        } catch (JSONException e) {
            Log.e("TdxStockInfo", "Fail to parse Tdx Stock info object", e);
            this.code = -1;
        }
    }

    public boolean isValidRecord() {
        return this.code > 0;
    }

    @Override
    public String getTitle() {
        return name + " " + pinyin + " " + String.format(Locale.CHINA, "%06d", code) + " " + industry;
    }
}
